<?php

/*
 * Successful payment for baby.
 */
include '../config.php';
include '../head.php';
session_start();
$buy_detail_id = $_GET['item_number'];
$amount = $_SESSION['amounts'];
$uid = $_COOKIE['gid'];
$code = $_SESSION['pre_code'];
/*
 * inserting data into buy_products.
 */
mysql_query("insert into salus_buy_product(`id`,`FK_fa_user_id`,`buy_detail_id`,`product_id`,`product_prize`,`date`) values(NULL,'" . $uid . "',$buy_detail_id,'2','" . $amount . "','" . date('Y-m-d') . "') ") or die(mysql_error());

/*
 * setting father or mother on baby_child_profile
 */
$s1 = mysql_query("select sex from salus_user_profile_detail where FK_fa_user_id ='" . $uid . "' ") or die(mysql_error());
while ($row = mysql_fetch_array($s1)) {
    if ($row['sex'] == 'M') {
        $idd = 'father_id';
    } else {
        $idd = 'mother_id';
    }
}
mysql_query("insert into baby_child_profile_detail (bid,buyer_id," . $idd . ") values(NULL,'" . $uid . "','" . $uid . "') ") or die(mysql_error());
$bid = mysql_insert_id();

/*
 * creating folders on Baby.
 */
$old = umask(0);
//$dir_path = '/home/salusban/www/salusbank.ch/salusbaby/storage/';
    $dir_path = '/var/www/html/salusbaby/storage/';
mkdir($dir_path . $bid, 0777) or die('Error1');
mkdir($dir_path . $bid . '/folders', 0777) or die('Error2');
mkdir($dir_path . $bid . '/folders/pregnancy', 0777) or die('Error3');
mysql_query("insert into baby_folders(sr,bid,folder)values(NULL,$bid,'pregnancy')") or die(mysql_error());
mkdir($dir_path . $bid . '/folders/pre-pregnancy', 0777) or die('Error4');
mysql_query("insert into baby_folders(sr,bid,folder)values(NULL,$bid,'pre-pregnancy')") or die(mysql_error());
umask($old);

/*
 * updating pre-paid code table
 */
if($code!=''){
    $code_id = $_SESSION['code_id'];
    mysql_query("update salus_prepaid_codes set user_id='".$uid."' where prepaid_code ='".$code."' ") or die(mysql_error());
}

?>
<title>Successful Payment</title>
<?php include '../header_profile.php'; ?>
<body>
    <div id="wrapper">
        <div id="mainContent">
            Congratulations...!! <br>Your Account created for SalusBaby.
        </div>
    </div>
</body>